package swd.work.generator.v2.java.bean;

import javax.servlet.jsp.*;
import javax.servlet.ServletRequest;

public class DataViewBean {
    private JspWriter gout = null;
    private ServletRequest greq=null;

    public DataViewBean(PageContext pageContext,ServletRequest request) {
        gout=pageContext.getOut();
        greq=request;
    }

    public void outputTextField(String pstrStatement,String pstrFieldName){
        try{
            gout.print(pstrStatement);
            gout.println("：<input type=\"text\" maxlength=\"255\" size=\"50\" name=\"" +
                         pstrFieldName + "\" value=\"" +
                         (greq.getParameter(pstrFieldName) != null &&
                          !greq.getParameter(pstrFieldName).equals("") ?
                          greq.getParameter(pstrFieldName) : "") + "\"/><br />");
        }
        catch(Exception e){
            System.out.println("Exception from DataViewBean.outputTextField(\"" + pstrStatement + "\",\"" + pstrFieldName + "\")==>" + e.toString());
        }
    }

    public void outputOptionTag(String pstrSelectName,String pstrOptionValue,String pstrOptionDisplay,int pintLoop){
        try{
            gout.print("<option ");
            gout.print(greq.getParameterValues(pstrSelectName)!=null && greq.getParameterValues(pstrSelectName)[pintLoop].equals(pstrOptionValue) ? " selected " : "");
            gout.println("value='" + pstrOptionValue + "'>" + pstrOptionDisplay + "</option>");
        }
        catch(Exception e){
            System.out.println("Exception from DataViewBean.outputOptionTag(\"" + pstrSelectName + "\",\"" + pstrOptionValue + "\",\"" + pstrOptionDisplay + "\"," + String.valueOf(pintLoop) + ")==>" + e.toString());
        }
    }
}
